package simple.cat.servlet;

import simple.cat.server.Request;
import simple.cat.server.Response;
import simple.cat.util.HttpProtocolUtil;

import java.nio.charset.StandardCharsets;

/**
 * @author zheng9feng
 * @Description
 * @Date 2020/12/29 07:34
 */
public class DemoServlet extends HttpServlet {
	/**
	 * 处理get请求
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@Override
	void doGet(Request request, Response response) throws Exception {
		String responseContent = "<h2>this is get request from demo-2</h2>";
		response.output(HttpProtocolUtil.getHttpHeader4Success(responseContent.getBytes(StandardCharsets.UTF_8).length) + responseContent);
	}
	
	/**
	 * 处理post请求
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@Override
	void doPost(Request request, Response response) throws Exception {
		String responseContent = "<h2>this is post request from demo-2</h2>";
		response.output(HttpProtocolUtil.getHttpHeader4Success(responseContent.getBytes(StandardCharsets.UTF_8).length) + responseContent);
	}
}
